<#-- 导入模版定义文件-->
<#include "../template/template_editPage.ftl">
<@edit title="家族活动管理">

<body class="input">
<script type="text/javascript" charset="utf-8" src="${web_static}/kindeditor/kindeditor.js"></script>
<script type="text/javascript" charset="utf-8" src="${web_static}/kindeditor/lang/zh_CN.js"></script>
<script>
	$().ready( function() {
	
		var $validateErrorContainer = $("#validateErrorContainer");
		var $validateErrorLabelContainer = $("#validateErrorContainer ul");
		var $validateForm = $("#inputForm");
		var $tab = $("#tab");
	
		// Tab效果
		$tab.tabs(".tabContent", {
			tabs: "input"
		});
		
		// 表单验证
		$validateForm.validate({
			errorContainer: $validateErrorContainer,
			errorLabelContainer: $validateErrorLabelContainer,
			wrapper: "li",
			errorClass: "validateError",
			ignoreTitle: true,
			rules: {
				"activityInfo.activityTitle": {
						required: true,
						maxlength:100
				},
				"activityInfo.bigClassId": {
						required: true
				}
				,
				"activityInfo.smallClassId": {
						required: true
				}
				,
				"activityInfo.beginTime": {
						required: true
				}
				,
				"activityInfo.endTime": {
						required: true
				}
				,
				"activityInfo.activityPlace": {
						required: true,
						maxlength:100
				}
				,
				"activityInfo.stock": {
						required: true,
						digits:true
				},
				"activityInfo.originalPrice": {
						number:true
				},
				"activityInfo.preferentialPrice": {
						number:true
				},
				"activityInfo.activityType": {
						required: true
				},
				"activityInfo.introduction": {
						maxlength:200
				}
			},
			messages: {
				"activityInfo.activityTitle": {
						required: "请填写活动标题",
						maxlength: "活动标题必须在100个字符以内"
				},
				"activityInfo.bigClassId": {
						required: "请选择活动大类"
				} ,
				"activityInfo.smallClassId": {
						required: "请选择活动小类"
				} ,
				"activityInfo.beginTime": {
						required: "请选择活动起止时间"
				} ,
				"activityInfo.endTime": {
						required: "请选择活动起止时间"
				} ,
				"activityInfo.activityPlace": {
						required: "请填写活动地点",
						maxlength: "活动地点必须在100个字符以内"
				} ,
				"activityInfo.stock": {
						required: "请填写活动库存",
						digits: "库存必须是整数"
				} ,
				"activityInfo.originalPrice": {
						number: "请填写正确的活动金额"
				} ,
				"activityInfo.preferentialPrice": {
						number: "请填写正确的活动金额"
				},
				"activityInfo.activityType": {
						required: "请选择活动类别"
				},
				"activityInfo.introduction": {
						maxlength:"活动简介必须在200个字符以内"
				}
			},
			submitHandler: function(form) {
				$(form).find(":submit").attr("disabled", true);
				form.submit();
			}
		});
		<#if actionErrors??&&(actionErrors?size > 0)>
			$.dialog({type: "warn", content: "<#list actionErrors as list>${list}<br></#list>",
			 modal: true, autoCloseTime: 5000});
		</#if>
	});
	
KindEditor.ready(function(K) {
	var editor1 = K.create('textarea[name="content"]', {
		cssPath : '${web_static}/kindeditor/plugins/code/prettify.css',
		uploadJson : '${web_base}/go/activity!imgUpload.htm',
		fileManagerJson : '${web_base}/go/activity!fileManager.htm',
		allowFileManager : true,
		afterCreate : function() {
			var self = this;
			K.ctrl(document, 13, function() {
				self.sync();
				document.forms['inputForm'].submit();
			});
			K.ctrl(self.edit.doc, 13, function() {
				self.sync();
				document.forms['inputForm'].submit();
			});
		}
	});
});
	
	
	function showDiv(picId,imgdiv,imgShow){
   		new uploadPreview({ UpBtn: picId, DivShow: imgdiv, ImgShow: imgShow });
	}
	
	function clearImg(imgId,imgShow){
		var obj = document.getElementById(imgId) ;   
		obj.outerHTML=obj.outerHTML;  
		
		$('#'+imgShow).attr("src", "");
	}
	
	
	//选择小类
	function changeSmallClass(){
			var bigClassId = $('#bigClassId').val();
			var html = '';
	        $.ajax({
	            type:"POST",
	            async:false,
	            url:"${web_base}/go/activity!getSmallClasses.htm",
	            data:{bigClassId:bigClassId},
	            success:function (msg) {
	            	if(msg != null && msg != '' && msg != undefined){
		                var list = eval("(" + msg + ")");
		                	html += '<option>请选择小类</option>';
						 $.each(list,function(n,value) {
						 	var c = value.classId;
						 	html += '<option value="'+c+'">' + value.className+ '</option>';
		       			}); 
	            	}else{
	            		$.dialog({type:"warn", content:"查询小类信息异常", modal:true, autoCloseTime:5000});
	            	}
	            }
	        });
	         $('#smallClassId').html(html);
	}
	
	function changeSubClass(){
		var smallClassId = $('#smallClassId').val();
			var html = '';
	        $.ajax({
	            type:"POST",
	            async:false,
	            url:"${web_base}/go/activity!getSmallClassDetail.htm",
	            data:{smallClassId:smallClassId},
	            success:function (msg) {
	            	if(msg != null && msg != '' && msg != undefined){
		                var smallInfo = eval("(" + msg + ")");
		                html = smallInfo.subClassId;
	            	}else{
	            		$.dialog({type:"warn", content:"查询小类子类信息异常", modal:true, autoCloseTime:5000});
	            	}
	            }
	        });
	        $('#smallClassSubId').val(html);
	}
	
</script>

<div class="body">
		<div class="inputBar">
			<h1><span class="icon">&nbsp;</span><#if activityId??>编辑活动<#else>新增活动</#if></h1>
		</div>
		<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
			<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
				<ul></ul>
			</div>
		</div>	
		
		<form id="inputForm" name="inputForm" class="validate" action="<#if activityId??>${web_base}/go/activity!edit.htm<#else>${web_base}/go/activity!save.htm</#if>" method="post" enctype="multipart/form-data">
			<input type="hidden" name="activityInfo.activityId" class="formText {required: true}" value="${(activityInfo.activityId)!}" />
			<input type="hidden" name="activityInfo.activityContentUrl" class="formText {required: true}" value="${(activityInfo.activityContentUrl)!}" />
			<table class="inputTable tabContent">
				<tr>
					<th>
						活动标题：
					</th>
					<td>
						<input type="text"  name="activityInfo.activityTitle" class="formText {required: true}" value="${(activityInfo.activityTitle)!}" />
						<label id="labelUrl" class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						所属分类：
					</th>
					<td>
						<select name="activityInfo.bigClassId" class="{required: true}" id="bigClassId" style="font-size: 14px"  onchange="changeSmallClass()">
						    <option value="" >请选择大类</option>
							<#if bigClassList??>
                       		<#list bigClassList as obj>
	                            <option value="${(obj.classId)!}" <#if activityInfo?? && activityInfo.bigClassId?? && activityInfo.bigClassId=="${obj.classId!}">selected="selected"</#if>>
		                              ${(obj.className)!}
                               </option>
		                     </#list>
		                    </#if>
						</select>
						<select name="activityInfo.smallClassId" id="smallClassId" class="{required: true}" style="font-size: 14px" onchange="changeSubClass()">
					   		<option>请选择小类</option>
					   		<#if smallClassList??>
                       		<#list smallClassList as obj>
					   		 <option value="${(obj.classId)!}" <#if activityInfo?? && activityInfo.smallClassId?? && activityInfo.smallClassId=="${obj.classId!}">selected="selected"</#if>>
		                              ${(obj.className)!}
                               </option>
                                </#list>
		                    </#if>
					    </select>
					    <input type="text"  name="activityInfo.smallClassSubId" id="smallClassSubId" class="formText {required: true}" value="${(activityInfo.smallClassSubId)!}" />
					    <label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						是否置顶：
					</th>
					<td>
						<input type="checkbox" name="activityInfo.isTop"  value="1"  <#if activityInfo?? && activityInfo.isTop?? && activityInfo.isTop=="1">checked="checked"</#if>/>
					</td>
				</tr>
				<tr>
					<th>
						是否限时特惠：
					</th>
					<td>
						<input type="checkbox" name="activityInfo.isLimitTime"  value="1"  <#if activityInfo?? && activityInfo.isLimitTime?? && activityInfo.isLimitTime=="1">checked="checked"</#if>/>
					</td>
				</tr>
				<tr>
					<th>
						关键字：
					</th>
					<td>
						 <input type="text"  name="activityInfo.keyword" class="formText {}" value="${(activityInfo.keyword)!}" />
					</td>
				</tr>
				<tr>
					<th>
						活动类别：
					</th>
					<td>
						<input type="radio" name="activityInfo.activityType" class="{required: false}" value="1" <#if activityInfo?? && activityInfo.activityType?? && activityInfo.activityType?contains("1")>checked="checked"</#if> />免费
						<input type="radio" name="activityInfo.activityType" class="{required: false}" value="3" <#if activityInfo?? && activityInfo.activityType?? && activityInfo.activityType?contains("3")>checked="checked"</#if> />直接购买
						<input type="radio" name="activityInfo.activityType" class="{required: false}" value="2" <#if activityInfo?? && activityInfo.activityType?? && activityInfo.activityType?contains("2")>checked="checked"</#if> />拼团
					</td>
				</tr>
				<tr>
					<th>
						活动费用：
					</th>
					<td>
						<input type="text"  name="activityInfo.originalPrice" class="formText {required: true}" value="${(activityInfo.originalPrice)!}" />--
						<input type="text"  name="activityInfo.preferentialPrice" class="formText {required: true}" value="${(activityInfo.preferentialPrice)!}" />
					</td>
				</tr>
				<tr>
					<th>
						报名起止时间：
					</th>
					<td>
						<input type="text" id="signBenginTime" name="activityInfo.signUpBeginTime"
                          onclick="WdatePicker({skin:'whyGreen',startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${(activityInfo.signUpBeginTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth" >
				     <span>--</span> <input type="text" id="signEndTime" name="activityInfo.signUpEndTime"
                          onclick="WdatePicker({skin:'whyGreen',startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'signBenginTime\')}'})"
                          value="${(activityInfo.signUpEndTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth">
					</td>
				</tr>
				<tr>
					<th>
						活动起止时间：
					</th>
					<td>
						<input type="text" id="beginTime" name="activityInfo.beginTime"
                          onclick="WdatePicker({skin:'whyGreen',startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${(activityInfo.beginTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth" >
				     <span>--</span> <input type="text" id="endTime" name="activityInfo.endTime"
                          onclick="WdatePicker({skin:'whyGreen',startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'beginTime\')}'})"
                          value="${(activityInfo.endTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth">
					</td>
				</tr>
				<tr>
					<th>
						活动地点：
					</th>
					<td>
					<input type="text"  name="activityInfo.activityPlace" id="" class="formText {required: true}" value="${(activityInfo.activityPlace)!}" />
					</td>
				</tr>
				<tr>
					<th>
						活动库存：
					</th>
					<td>
					<input type="text"  name="activityInfo.stock" id="" class="formText {required: true}" value="${(activityInfo.stock)!}" />
					</td>
				</tr>
				<tr>
					<th>
						团购人数：
					</th>
					<td>
					<input type="text"  name="activityInfo.groupPeoples" id="" class="formText {required: true}" value="${(activityInfo.groupPeoples)!}" />
					</td>
				</tr>
				<tr>
					<th>
						预览图：
					</th>
					<td>
					<div style="float:left">
    				<input type="file" id="preActivityPhoto" name="preActivityPhoto" value="添加图片" onclick="showDiv('preActivityPhoto','imgdiv1','imgShow1')"/>
						<div id="imgdiv1">
							<img id="imgShow1" width="160" height="100"  src="${(web_base + (activityInfo.prePhotoPath))!}"/>
							<span class="spanLink" onclick="clearImg('imgdiv1','imgShow1')" title="删除">[删除]</span>
						</div>
					</div>
					</td>
				</tr>
				<tr>
					<th>
						报名页大图：
					</th>
					<td>
					<div style="float:left">
    				<input type="file" id="signupPhoto" name="signupPhoto" value="添加图片" onclick="showDiv('signupPhoto','imgdiv2','imgShow2')"/>
						<div id="imgdiv2">
							<img id="imgShow2" width="180" height="120" src="${(web_base + (activityInfo.signupPhotoPath))!}"/>
							<span class="spanLink" onclick="clearImg('imgdiv2','imgShow2')" title="删除">[删除]</span>
						</div>
					</div>
					</td>
				</tr>
				<tr>
					<th>简介：</th>
					<td>
						<textarea rows="8" cols="50" name="activityInfo.introduction" class="formText {}" >${(activityInfo.introduction)!}</textarea>
					</td>
				</tr>
				<tr>
					<th>活动内容：</th>
					<td>
						<textarea id="editor_id" name="content" style="width:800px;height:600px;">${(activityInfo.activityContent)!}</textarea>
						<strong><span style="color:#E53333;">图片支持格式：gif,jpg,jpeg,png,bmp</span></strong><br />
						<strong><span style="color:#E53333;"> flash支持格式：swf,flv</span></strong><br />
						<strong><span style="color:#E53333;"> media支持格式：swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb</span></strong><br />
						<strong><span style="color:#E53333;"> 文件支持格式：doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2</span></strong><br />
					</td>
				</tr>
			</table>
			<div class="buttonArea">
				<input type="submit" class="formButton" value="提  交" hidefocus="true" />&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="取  消" hidefocus="true" />
			</div>
		</form>
	</div>
</body>
</@edit>